/**
Marvin Project <2007-2013>
http://www.marvinproject.org

License information:
http://marvinproject.sourceforge.net/en/license.html

Discussion group:
https://groups.google.com/forum/#!forum/marvin-project
*/

package net.marvin.plugins.image.color.invert;

import net.marvin.framework.gui.MarvinAttributesPanel;
import net.marvin.framework.image.MarvinImage;
import net.marvin.framework.image.MarvinImageMask;
import net.marvin.framework.plugin.MarvinAbstractImagePlugin;
import net.marvin.framework.util.MarvinAttributes;

/**
 * Invert the pixels color.
 * @author Gabriel Ambrosio Archanjo
 * @version 1.0 02/28/2008
 */
public class Invert extends MarvinAbstractImagePlugin
{
	public void load(){}

	public MarvinAttributesPanel getAttributesPanel(){
		return null;
	}
	
	public void process
	(
		MarvinImage imageIn, 
		MarvinImage imageOut,
		MarvinAttributes attributesOut,
		MarvinImageMask mask, 
		boolean previewMode
	)
	{
		boolean[][] l_arrMask = mask.getMask();
		
		int r, g, b;
		for (int x = 0; x < imageIn.getWidth(); x++) {
			for (int y = 0; y < imageIn.getHeight(); y++) {
				if(l_arrMask != null && !l_arrMask[x][y]){
					continue;
				}
				r = (255-(int)imageIn.getIntComponent0(x, y));
				g = (255-(int)imageIn.getIntComponent1(x, y));
				b = (255-(int)imageIn.getIntComponent2(x, y));

				imageOut.setIntColor(x,y,imageIn.getAlphaComponent(x, y), r,g,b);
			}
		}
	}
}
